<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListUfTitle}"></h:outputText>
        </ui:define>
        
        <ui:define name="menuLateral">
            
            <h:form id="formLateralMenuUfList">
                
            </h:form>
            
        </ui:define>
        
        <ui:define name="body">
            <h:form id="formUfList">
                
                <h:panelGroup id="messagePanel" layout="block">
                    <p:growl/>
                </h:panelGroup>
                
                <h:panelGroup>
                    <p:dataTable id="tableUf" value="#{ufController.items}" var="item" style="border:solid 1px" paginator="true" 
                                 rows="10" emptyMessage="#{bundle.ListUfEmpty}">
                
                        <f:facet name="header">#{bundle.ListUfTitle}</f:facet>
                        
                        <p:column id="sigla" sortBy="#{item.sigla}" filterBy="#{item.sigla}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListUfTitle_sigla}"/>
                            </f:facet>
                            <h:outputText value="#{item.sigla}"/>
                        </p:column>
                        
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListUfTitle_descricao}"/>
                            </f:facet>
                            <h:outputText value="#{item.descricao}"/>
                        </p:column>
                        
                        <p:column>
                            <f:facet name="header">
                                <p:commandButton actionListener="#{ufController.prepareCreate}" value="#{bundle.ListUfCreateLink}" update=":formUfCreate:pgUfCreate" oncomplete="dialogUfCreate.show()"/>
                            </f:facet>
                            <p:commandButton actionListener="#{ufController.prepareEdit}" value="#{bundle.ListUfEditLink}" update=":formUfEdit:pgUfEdit" oncomplete="dialogUfEdit.show()"/>
                            <p:commandButton actionListener="#{ufController.destroy}" value="#{bundle.ListUfDestroyLink}" update=":formUfList:tableUf" ajax="false"/>
                        </p:column>
                        
                    </p:dataTable>
                </h:panelGroup>
                
            </h:form>
            
            <h:form id="formUfCreate">

                <p:dialog header="Nova UF" widgetVar="dialogUfCreate" resizable="false" modal="true" showEffect="slide">
                    <p:panelGrid id="pgUfCreate" columns="2">
                        <h:outputLabel value="#{bundle.CreateUfLabel_sigla}" for="sigla" />
                        <p:inputText id="sigla" value="#{ufController.selected.sigla}" title="#{bundle.CreateUfTitle_sigla}" required="true" requiredMessage="#{bundle.CreateUfRequiredMessage_sigla}"/>
                        <h:outputLabel value="#{bundle.CreateUfLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{ufController.selected.descricao}" title="#{bundle.CreateUfTitle_descricao}" required="true" requiredMessage="#{bundle.CreateUfRequiredMessage_descricao}"/>
                        <p:commandButton actionListener="#{ufController.create}" update=":formUfList:tableUf" value="#{bundle.CreateUfSaveLink}" oncomplete="#{ufController.prepareCreate}" ajax="false" />
                        <p:commandButton value="Limpar" type="reset" update=":formUfCreate:pgUfCreate" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>
                
            </h:form>
            
            <h:form id="formUfEdit">

                <p:dialog header="Editar UF" widgetVar="dialogUfEdit" resizable="false" modal="true" showEffect="slide">
                    <p:panelGrid id="pgUfEdit" columns="2">
                        <h:outputLabel value="#{bundle.EditUfLabel_sigla}" for="sigla" />
                        <p:inputText id="sigla" value="#{ufController.selected.sigla}" title="#{bundle.EditUfTitle_sigla}" required="true" requiredMessage="#{bundle.EditUfRequiredMessage_sigla}"/>
                        <h:outputLabel value="#{bundle.EditUfLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{ufController.selected.descricao}" title="#{bundle.EditUfTitle_descricao}" required="true" requiredMessage="#{bundle.EditUfRequiredMessage_descricao}"/>
                        <p:commandButton actionListener="#{ufController.update}" update=":formUfList:tableUf" value="#{bundle.EditUfSaveLink}" oncomplete="dialogUfEdit.hide()" ajax="false" />
                        <p:commandButton value="Cancelar" oncomplete="dialogUfEdit.hide()" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>
                
            </h:form>

        </ui:define>
    </ui:composition>

</html>
